Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Vintasoft.Imaging.ImageRendering
Imports System.Globalization

Namespace Imaging
	Public Partial Class ImageRenderingRequirementsForm
		Inherits Form

		#Region "Fields"

		Private _requirements As New Dictionary(Of String, Single)()

		Private _codes As String() = New String() {"Bmp", "Jpeg", "Jpeg2000", "Tiff", "Png", "Pdf"}

		#End Region



		#Region "Constructors"

		Public Sub New()
			InitializeComponent()
		End Sub

		Public Sub New(renderingRequirements As ImageRenderingRequirements)
			Me.New()
			_renderingRequirements = renderingRequirements

			ShowSettings()
		End Sub

		#End Region



		#Region "Properties"

		Private _renderingRequirements As ImageRenderingRequirements
		Public ReadOnly Property RenderingRequirements() As ImageRenderingRequirements
			Get
				Return _renderingRequirements
			End Get
		End Property

		#End Region



		#Region "Methods"

		Private Sub ShowSettings()

			For i As Integer = 0 To _codes.Length - 1
				Dim mpx As Single
				If _renderingRequirements.GetRequirement(_codes(i), mpx) Then
					codecComboBox.Items.Add(_codes(i))
					_requirements.Add(_codes(i), mpx)
				End If
			Next

			codecComboBox.SelectedIndex = 2
		End Sub

		Private Function SetSettings() As Boolean
			For i As Integer = 0 To _codes.Length - 1
				_renderingRequirements.SetRequirement(_codes(i), _requirements(_codes(i)))
			Next
			Return True
		End Function

		Private Sub buttonCancel_Click(sender As Object, e As EventArgs)
			DialogResult = DialogResult.Cancel
		End Sub

		Private Sub buttonOk_Click(sender As Object, e As EventArgs)
			If SetSettings() Then
				DialogResult = DialogResult.OK
			End If
		End Sub

		Private Sub megapixelsComboBox_TextChanged(sender As Object, e As EventArgs)
			Try
				_requirements(DirectCast(codecComboBox.SelectedItem, String)) = Single.Parse(megapixelsComboBox.Text, CultureInfo.InvariantCulture)
			Catch ex As Exception
				DemosTools.ShowErrorMessage(ex)
			End Try
		End Sub

		Private Sub codecComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
			megapixelsComboBox.Text = _requirements(DirectCast(codecComboBox.SelectedItem, String)).ToString(CultureInfo.InvariantCulture)
		End Sub

		#End Region


	End Class
End Namespace
